﻿using Entity.BaseInfo.DTO.WarehousePosition;
using Entity.BaseInfo.View.WarehousePosition;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 仓位表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class WarehousePositionController : ControllerBase
    {
        /**
         * 仓位业务接口
         */
        private readonly WarehousePositionService _warehousePositionService;

        /**
         * 构造函数注入
         */
        public WarehousePositionController(WarehousePositionService warehousePositionService)
        {
            _warehousePositionService = warehousePositionService;
        }

        /// <summary>
        /// 获取仓位列表
        /// </summary>
        /// <param name="warehousePositionSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(WarehousePositionView), 200)]
        public async Task<IActionResult> GetWarehousePositionList([FromQuery] WarehousePostionSearchDTO warehousePositionSearchDTO)
        {
            var response = await _warehousePositionService.GetWarehousePositionList(warehousePositionSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增仓位
        /// </summary>
        /// <param name="warehousePositionAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddWarehousePosition([FromBody] WarehousePositionAddDTO warehousePositionAddDTO)
        {
            var response = await _warehousePositionService.AddWarehousePosition(warehousePositionAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新仓位
        /// </summary>
        /// <param name="warehousePositionUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutWarehousePosition([FromBody] WarehousePositionUpdateDTO warehousePositionUpdateDTO)
        {
            var response = await _warehousePositionService.PutWarehousePosition(warehousePositionUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除仓位
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteWarehousePosition([FromQuery] string Id)
        {
            var response = await _warehousePositionService.DeleteWarehousePosition(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取仓位列表
        /// </summary>
        /// <param name="warehousePositionSelectSearchDTO"></param>
        [HttpGet("Select")]
        [ProducesResponseType(typeof(WarehousePositionSelectView), 200)]
        public async Task<IActionResult> GetWarehousePositionList([FromQuery] WarehousePostionSelectSearchDTO warehousePositionSelectSearchDTO)
        {
            var response = await _warehousePositionService.GetWarehousePositionSelectList(warehousePositionSelectSearchDTO);
            return StatusCode(response.Status, response);
        }
    }
}
